<template>
  <view class="phxx-item-detail">
    <view class="content-box">
      <view class="title-box">基本信息</view>
      <view class="bottom block-back">
        <view class="uni-form-item" v-if="showErpFlag">
          <view class="title"><span style="color:red;">*</span>ERP订单</view>
          <view class="uni-select-box">
            <picker @change="handleERPListChange" :disabled="isDisabled" :value="itemList.billNo"
              mode="selector" :range="erpDataList" range-key="text">
              <view class="uni-input text-overflow-styl">{{itemList.billName || ''}}</view>
            </picker>

            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>供应商</view>
          <view class="uni-select-box">
            <input class="uni-input" v-model="searchSupplierText" :disabled="true"
              :class="{placeholder:searchSupplierText==='请选择供应商'}" @click="openSupplierSearch" />
            <uni-icons type="forward" size="20" v-if="!showErpFlag || !isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>煤源</view>
          <view class="uni-select-box">
            <input class="uni-input" v-model="searchText" :disabled="true" :class="{placeholder:searchText==='请选择煤源'}"
              @click="openCoalSourceSearch" />
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>装货地</view>
          <view class="uni-select-box">
            <picker @change="handleLoadListChange" :disabled="isDisabled" :value="itemList.loadingSiteId"
              mode="selector" :range="loadList" range-key="text">
              <view class="uni-input text-overflow-styl">{{itemList.loadingSiteName || ''}}</view>
            </picker>

            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>卸货地</view>
          <view class="uni-select-box">
            <picker @change="handleDisChange" :disabled="isDisabled" :value="itemList.landingPlaceId" mode="selector"
              :range="dischargeList" range-key="text">
              <view class="uni-input text-overflow-styl">{{itemList.landingPlace || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>

        <view class="uni-form-item">
          <view class="title">卸货点</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.landingPointName" maxlength="50"
            :disabled="isDisabled" />
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>产品</view>
          <view class="uni-select-box">
            <picker :disabled="showErpFlag || isDisabled  || isDisabledMode" @change="handleProChange" :value="itemList.proId"
              mode="selector" :range="prochargeList" range-key="text">
              <view class="uni-input text-overflow-styl">{{itemList.proName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!showErpFlag || !isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>产品价格</view>
          <input class="uni-input" :class="{'disab-box':showErpFlag || isDisabled}" v-model="itemList.productPrice"
            :disabled="showErpFlag || isDisabled  || isDisabledMode || erpMessDisabled" />
          元/吨
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>拉运数量</view>
          <input class="uni-input" :class="{'disab-box':showErpFlag || isDisabled}" v-model="itemList.transportQuantity"
            @blur="formatTransportQuantity" :disabled="showErpFlag || isDisabled || erpMessDisabled" />
          吨
        </view>

        <view class="uni-form-item">
          <view class="demonstration title"><span style="color:red;">*</span>开始时间：</view>
          <w-picker :visible="poundListFlag" class="disab-box" v-if="showErpFlag || !isDisabled" mode="date" startYear="1900"
            endYear="2124" :value="itemList.startTime" :current="false" fields="second"
            @confirm="onConfirm($event,'startTime')" @cancel="onCancel" :disabled-after="false" ref="date1"></w-picker>
          <input class="uni-input prd-mess" :class="{'disab-box':showErpFlag || isDisabled || erpMessDisabled}" v-model="itemList.startTime"
            placeholder="请选择开始时间" @click="choseStartTimeFun" disabled="true"></input>
        </view>

        <view class="uni-form-item">
          <view class="demonstration title"><span style="color:red;">*</span>结束时间：</view>
          <w-picker :visible="endTimePickerFlag" v-if="showErpFlag || !isDisabled" mode="date" class="disab-box" startYear="1900"
            endYear="2124" :value="itemList.endTime" :current="false" fields="second"
            @confirm="onConfirm($event,'endTime')" @cancel="onCancel" :disabled-after="false" ref="date2"></w-picker>
          <input class="uni-input prd-mess" :class="{'disab-box':showErpFlag ||isDisabled || erpMessDisabled}" v-model="itemList.endTime"
            placeholder="请选择结束时间" disabled="true" @click="choseEndTimeFun"></input>
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>收货人手机号</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.purchaserPhone"
            @input="validatePhoneNumber" :disabled="isDisabled" />
        </view>

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>结算依据</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled  || isDisabledMode" @change="weitSettllChange" value="0" mode="selector"
              :range="weightSettlementList" range-key="text">
              <view class="uni-input">{{weightSettBaName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>采购方式</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled  || isDisabledMode" @change="procuretMethodChange" value="0" mode="selector"
              :range="procurementMethodList" range-key="text">
              <view class="uni-input">{{proMethodName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>购销属性</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled  || isDisabledMode" @change="purchaseSalesChange" value="0" mode="selector"
              :range="purchaseSalesAttList" range-key="text">
              <view class="uni-input">{{purchaseAndSalesAttName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item" v-if="isDisabled">
          <view class="title">铅封照片</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" :value="itemList.sealPhotograph" mode="selector" :range="sealPhotographList"
              range-key="text">
              <view class="uni-input">{{sealPhotographName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>货款路损配置</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="payReloadSetChange" :value="itemList.paymentRoadLossSetting"
              mode="selector" :range="payReloadSetList" range-key="text">
              <view class="uni-input">{{payRoadName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item" v-if="itemList.paymentRoadLossSetting == 1">
          <view class="title"><span style="color:red;">*</span>货款合理路损</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.paymentRoadLoss"
            :disabled="isDisabled" />
          吨
        </view>

        <view class="uni-form-item" v-if="itemList.paymentRoadLossSetting == 1">
          <view class="title"><span style="color:red;">*</span>货款路损单价</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.paymentRoadLossPrice"
            :disabled="isDisabled" />
          元/吨
        </view>

        <view class="uni-form-item" v-if="itemList.paymentRoadLossSetting == 1">
          <view class="title"><span style="color:red;">*</span>货款路损计算规则</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handlePaCalculateRule" :value="itemList.paymentRoadLossRule"
              mode="selector" :range="roadLossCalculateRuleList" range-key="text">
              <view class="uni-input">{{paymentRuleName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item" v-if="planConfigShow === 2 || planConfigShow === 3">
          <view class="title">计划配置</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled  || isDisabledMode" @change="planConfigMethodChange"
              :value="itemList.planConfig" mode="selector" :range="planConfigList" range-key="text">
              <view class="uni-input">{{planConfigName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
      </view>
      <view class="title-box" v-if="status">运输信息</view>
      <!-- 运输信息 -->
      <view class="bottom block-back" v-if="status">

        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>运价</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.freight" @blur="formatFreight"
            :disabled="isDisabled">
          </input>
          元/吨
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>结算依据</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleSettlement" :value="itemList.settlementBasis" mode="selector"
              :range="settlementBasisList" range-key="text">
              <view class="uni-input">{{settlementBasisName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>是否计算路损</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleRoadLoss" :value="itemList.isCalculateRoadLoss"
              mode="selector" :range="isCalculateRoadLossList" range-key="text">
              <view class="uni-input">{{roadLossName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title">合理路损</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.reasonableRoadLoss"
            :disabled="isDisabled" />
          吨
        </view>
        <view class="uni-form-item">
          <view class="title">路损单价</view>
          <input class="uni-input" :class="{'disab-box':isDisabled}" v-model="itemList.roadLossPrice"
            :disabled="isDisabled" />
          元/吨
        </view>
        <view class="uni-form-item">
          <view class="title">路损计算规则</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleCalculateRule" :value="itemList.roadLossCalculateRule"
              mode="selector" :range="roadLossCalculateRuleList" range-key="text">
              <view class="uni-input">{{calculateRuleName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>抹零规则</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleErasureRule" :value="itemList.erasureRule" mode="selector"
              :range="erasureRuleList" range-key="text">
              <view class="uni-input">{{erasureRuleName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
      </view>
      <!-- 网贷信息 -->
      <view class="title-box" v-if="status1">网货信息</view>
      <view class="bottom block-back" v-if="status1">
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>网货公司</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleNetCargoCompanyChange" :value="itemList.netCargoCompanyId"
              mode="selector" :range="netCargoCompanyList" range-key="text">
              <view class="uni-input">{{itemList.netCargoCompanyName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>货主</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleCargoOwnerChange" :value="itemList.cargoOwnerId"
              mode="selector" :range="cargoownerList" range-key="text">
              <view class="uni-input">{{itemList.cargoOwnerName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
        <view class="uni-form-item">
          <view class="title"><span style="color:red;">*</span>承运公司</view>
          <view class="uni-select-box">
            <picker :disabled="isDisabled" @change="handleAgentChange" :value="itemList.agentId" mode="selector"
              :range="agentList" range-key="text">
              <view class="uni-input">{{itemList.agentName || ''}}</view>
            </picker>
            <uni-icons type="forward" size="20" v-if="!isDisabled" class="icons-box"></uni-icons>
          </view>
        </view>
      </view>
      <view>
        <view class="btns" v-if="!isEdit">
          <button type="primary" @click="handleClick" :disabled="loading">提交</button>
        </view>
        <view class="btn-detail half-width" v-if="isEdit && isShowBtns">
          <button class="button cancel" type="default" v-if="hasPermission" @click="cancel">取消计划</button>
          <button class="button update" v-if="hasPermissionFre" @click="updatePrice(itemList.id)">预约产品价格</button>
        </view>
      </view>
    </view>

    <select-search :show="isSourcePop" :title="'选择煤种'" :type="'radio'" :name="'label'" :value="'value'"
      :dataLists="filteredOptions" :param="itemList.coalSourceId" @search="searchSourceFn" @cancel="cancelSourceSelect"
      @submit="onSubmitSource"></select-search>
    <select-search :show="isSupplierPop" :title="'选择供应商'" :type="'radio'" :name="'text'" :value="'value'"
      :dataLists="supplierOptions" :param="itemList.supId" @search="searchSupplierFn" @cancel="cancelSupplierSelect"
      @submit="onSubmitSupplier"></select-search>
  </view>
</template>

<script>
  import {
    toast, getButtonShow
  } from '@/utils/common';
  import {
    getSupLists,
    getCoalSourceLists,
    getCoalPurOrderLists,
    getLoadLists,
    getProNameLists,
    getDisChargeLists,
    transportPlanCreate,
    freightUpdate,
    getCargoownerLists,
    getPurIds,
    getPurManagementLists,
    getPurOrderLinked,
    getPurOrderDatas,
    getAgentLists,
    getDetails,
    cancelOne,
    getERPMessLists,
    getDictDatas,
    getPlanConfig
  } from '@/api/transport.js';
  import {
    createPlan,
    getPlanDetail,
    cancelPlanDetail,
  getPlanERPDatas,
  getEnterBasic
  } from '@/api/tranplan.js';
  import {
    getDriverId, getTenantId
  } from '@/utils/auth'
  import {
    dictTansParams
  } from '@/utils/common.js';
  export default {
    data() {
      return {
        isPop: false,
        isSourcePop: false,
        isSupplierPop: false,
        linkedStatus: false,
        planConfigShow: undefined,
        loading: false,
        hasPermission: false,
        topNum: 0,
        popShow: false,
        erpMessDisabled:false,
        erpDataList:[],
        purShow: false,
        hasPermissionFre: false,
        searchText: '请选择煤源',
        searchTextOne: '请选择采购订单',
        searchSupplierText: '请选择供应商',
        options: ['选项1', '选项2', '选项3'],
        filteredOptions: [],
        PurOrderOptions: [],
        supplierOptions: [],
        settlementBasisName: '',
        roadLossName: '',
        calculateRuleName: '',
        paymentRuleName: '',
        erasureRuleName: '',
        poundListFlag: false,
        endTimePickerFlag: false,
        isDisabled: false,
        isDisabledMode: false,
        linkedStatusFlag: false,
        userId: undefined,
        purId: '',
        purchaseSalesAttList: [],
        procurementMethodList: [],
        payReloadSetList: [],
        planConfigList: [],
        sealPhotographList: [],
        weightSettlementList: [],
        coalSourceList: [],
        coalPurOrderList: [],
        coalSourceName: "",
        weightSettBaName: "",
        proMethodName: "",
        planConfigName: "",
        payRoadName: "",
        sealPhotographName: "",
        purchaseAndSalesAttName: "",
        searchData: {
          lat: '',
          lon: ''
        },
        itemList: {
          purchaseId: undefined,
          purchaser: undefined,
          billNo: undefined,
          billName: undefined,
          purchaserAbbreviation: undefined,
          supId: undefined,
          supplierName: undefined,
          supplierAbbreviation: undefined,
          loadingSiteId: undefined,
          loadingSiteName: undefined,
          landingPlaceId: undefined,
          landingPlace: undefined,
          landingPoint: undefined,
          landingPointName: undefined,
          coalSourceId: undefined,
          purchaseOrderSourceId: undefined,
          purchaseOrderSourceNo: undefined,
          purchaseOrderSourceName: undefined,
          proId: undefined,
          proName: undefined,
          productPrice: undefined,
          weightSettlementBasis: 1,
          paymentRoadLossSetting: 0,
          paymentRoadLoss: undefined,
          paymentRoadLossPrice: undefined,
          paymentRoadLossRule: undefined,
          procurementMethod: 1,
          planConfig: 0,
          sealPhotograph: undefined,
          purchaseAndSalesAttributes: 1,
          transportQuantity: undefined,
          startTime: undefined,
          endTime: undefined,
          purchaserPhone: undefined,
          freight: undefined,
          settlementBasis: undefined,
          isCalculateRoadLoss: undefined,
          reasonableRoadLoss: undefined,
          roadLossPrice: undefined,
          roadLossCalculateRule: undefined,
          erasureRule: undefined,
          netCargoCompanyId: undefined,
          netCargoCompanyName: undefined,
          cargoOwnerId: undefined,
          cargoOwnerName: undefined,
          agentId: undefined,
          agentName: undefined,
          userId: undefined,
          updateFreight: undefined,
          companyId: undefined,
        },
        totalSeconds: 60,
        showErpFlag: false,
        showModal: false,
        newPrice: '',
        isEdit: true,
        isEdits: false,
        isShow: true,
        isShowBtns: false,
        supList: [],
        loadList: [],
        dischargeList: [],
        prochargeList: [],
        cargoownerList: [],
        agentList: [],
        netCargoCompanyList: [
        ],
        erasureRuleList: [
        ],
        roadLossCalculateRuleList: [
        ],
        isCalculateRoadLossList: [
        ],
        settlementBasisList: [
        ],
        landingPointNameList: [
        ],
        status: false,
        status1: false
      };
    },
  async onLoad(options) {
     let tenantId = getTenantId()
      let basicConfig =await getEnterBasic(tenantId)
      if (basicConfig.code == 200) {
        if (basicConfig.data?.erpDocking == 0) { 
          this.showErpFlag = true
          this.getERPDataList()
        }
      }
      let res = await getPlanConfig(tenantId)
      if (res.data != null) {
        this.planConfigShow = res.data.productCustomerStatus
      }
      this.getbuttonAuth()
      //获取字典
      await this.getLicenseTypeDict()
      await this.getCoalSourceList()
      //获取字典
      if (!!options) {
        this.isEdit = true
        if (!!options.id) {
          wx.setNavigationBarTitle({
            title: '运输计划'
          })
          this.getDetail(options.id)
        }
        else this.isEdit = false
      }
      this.userId = getDriverId()
      //获取当前登录的采购商id
      if (this.userId != undefined) {
        this.getPurId(this.userId);
      }
    },
    methods: {
      openSelectSearch() {
        if (!this.isDisabled) {
          this.isPop = true;
        }
      },
      openSupplierSearch() {
        if (this.erpMessDisabled || this.showErpFlag) {
          return
        }
        if (!this.isDisabled && !this.isDisabledMode) {
          this.isSupplierPop = true;
        }
      },
      openCoalSourceSearch() {
        if (!this.isDisabled && !this.isDisabledMode) {
          this.isSourcePop = true;
        }
      },
      searchFn(value) {
        this.PurOrderOptions = [...this.coalPurOrderList].filter(e => e.label.includes(value))
      },
      searchSourceFn(value) {
        this.filteredOptions = [...this.coalSourceList].filter(e => e.label.includes(value))
      },
      searchSupplierFn(value) {
        this.supplierOptions = [...this.supList].filter(e => e.text.includes(value))
      },
      onSubmit(data) {
        this.searchTextOne = data.label
        this.cancelSelect()
        this.itemList.purchaseOrderSourceId = data.value
        this.itemList.purchaseOrderSourceName = data.label
        this.itemList.purchaseOrderSourceNo = data.text
        //获取采购订单信息去填充数据
        if (this.itemList.purchaseOrderSourceId) {
          this.getPurOrderLits(data.value)
        }
      },
      onSubmitSource(data) {
        this.searchText = data.label
        this.itemList.coalSourceId = data.value
        this.coalSourceName = data.label
        this.cancelSourceSelect()
      },
      onSubmitSupplier(data) {
        this.searchSupplierText = data.text
        this.itemList.supId = data.value
        this.itemList.supplierName = data.text
        this.itemList.supplierAbbreviation = data.supplierAbbreviation
        this.getProNameList(this.itemList.supId);
        this.cancelSupplierSelect()
      },
      cancelSelect() {
        this.isPop = false;
        this.PurOrderOptions = [...this.coalPurOrderList]
      },
      cancelSourceSelect() {
        this.isSourcePop = false;
        this.filteredOptions = [...this.coalSourceList]
      },
      cancelSupplierSelect() {
        this.isSupplierPop = false;
        this.supplierOptions = [...this.supList]
      },
      async getPurOrderLits(id) {
        try {
          let res = await getPurOrderDatas(id)
          if (res.code == 0) {
            if (res.data != null) {
              this.itemList.supId = res.data.supplierId
              this.searchSupplierText = res.data.supplierName
              this.itemList.supplierName = res.data.supplierName
              this.searchText = res.data.coalSourceName
              this.coalSourceName = res.data.coalSourceName
              this.itemList.coalSourceId = res.data.coalSourceId
              this.itemList.proId = res.data.productId
              this.itemList.proName = res.data.productName
              this.itemList.productPrice = res.data.productPrice
              this.itemList.loadingSiteId = res.data.loadingSiteId
              this.itemList.loadingSiteName = res.data.loadingSiteName
              this.itemList.landingPlaceId = res.data.landingPlaceId
              this.itemList.landingPlace = res.data.landingPlaceName
              this.itemList.supplierAbbreviation = res.data.supplierAbbreviation
              this.itemList.weightSettlementBasis = res.data.settlementBasis
              this.weightSettlementList.forEach(item => {
                if (item.value == res.data.settlementBasis) {
                  this.weightSettBaName = item.text
                }
              })
              this.itemList.procurementMethod = res.data.procurementMethod
              this.procurementMethodList.forEach(item => {
                if (item.value == res.data.procurementMethod) {
                  this.proMethodName = item.text
                }
              })
              this.itemList.purchaseAndSalesAttributes = res.data.purchaseAndSalesAttributes
              this.purchaseSalesAttList.forEach(item => {
                if (item.value == res.data.purchaseAndSalesAttributes) {
                  this.purchaseAndSalesAttName = item.text
                }
              })
              this.isDisabledMode = true
            }
          }
        } catch (e) {
          return false;
        }
      },
      purShowFun(e) {
        if (this.isDisabled) return
        this.topNum = e.currentTarget.offsetTop + 38
        this.purShow = true
      },
      onInput(e) {
        this.filteredOptions = []
        this.searchText = e;
        if (!!this.searchText) {
          let temps = this.coalSourceList.filter(option => option.label.toLowerCase().includes(this.searchText.toLowerCase()));
          this.itemList.coalSourceId = temps[0].value
          this.coalSourceName = temps[0].label
          this.filteredOptions = temps
        } else {
          this.filteredOptions = this.coalSourceList
        }
      },
      onChange(e) {
        // 处理 picker-view 的 change 事件
      },
      onOptionTap(option) {
        this.searchText = option;
        this.filteredOptions = [];
        // 执行其他逻辑，比如提交选项
      },
      async getbuttonAuth() {
        //调用公共方法
        this.hasPermission = await getButtonShow('plan:cancel')
        this.hasPermissionFre = await getButtonShow('plan:datePrice')
      },
      async getLicenseTypeDict() {
        let datas = await getDictDatas()
        this.purchaseSalesAttList = dictTansParams(datas.data, 'buy_sell_attribute', 1)
        this.purchaseAndSalesAttName = this.purchaseSalesAttList[0].text
        this.itemList.purchaseAndSalesAttributes = this.purchaseSalesAttList[0].value

        this.procurementMethodList = dictTansParams(datas.data, 'procurement_method', 1)
        this.proMethodName = this.procurementMethodList[0].text
        this.itemList.procurementMethod = this.procurementMethodList[0].value

        this.payReloadSetList = dictTansParams(datas.data, 'enable_status', 0)
        this.payRoadName = this.payReloadSetList[0].text
        this.itemList.paymentRoadLossSetting = this.payReloadSetList[0].value

        this.planConfigList = dictTansParams(datas.data, 'plan_config', 1)
        this.planConfigName = this.planConfigList[0].text
        this.itemList.planConfig = this.planConfigList[0].value

        this.sealPhotographList = dictTansParams(datas.data, 'enable_status', 1)
        this.weightSettlementList = dictTansParams(datas.data, 'weight_settlement_basis', 1)
        this.weightSettBaName = this.weightSettlementList[0].text
        this.itemList.weightSettlementBasis = this.weightSettlementList[0].value

        this.netCargoCompanyList = dictTansParams(datas.data, 'network_freight', 1)
        this.erasureRuleList = dictTansParams(datas.data, 'erasure_rule', 1)
        this.roadLossCalculateRuleList = dictTansParams(datas.data, 'road_loss_calculate_rule', 1)
        this.isCalculateRoadLossList = dictTansParams(datas.data, 'is_calculate_road_loss', 1)
        this.settlementBasisList = dictTansParams(datas.data, 'settlement_basis', 1)
        this.landingPointNameList = dictTansParams(datas.data, 'landing_point', 1)
      },
      async getPurId(userId) {
        let list = await getPurIds(userId)
        this.purId = list.data
        if (this.purId != '' || this.purId != undefined || this.purId != null) {
          //获取基本，调运、网贷状态 + 关联订单状态
          this.getPurManagementList(this.purId);
          //获取供应商数据源
          this.getSupList(this.purId);
          //获取装货地数据源
          const data = {
            id: this.purId,
            type: 1
          };
          this.getLoadList({
            type: 1
          });
          //获取卸货地数据源
          const datas = {
            type: 2
          };
          this.getDisChargeList(datas);
          //获取采购订单数据源
          this.getPurOrderList(this.purId)
        }
      },
      //获取基本，调运、网贷状态,根据状态的开启关闭来展示页面
      async getPurManagementList(purId) {
        let ManageData = await getPurManagementLists(purId)
        this.itemList.purchaseId = ManageData.data.id
        this.itemList.purchaser = ManageData.data.purchaserName
        this.itemList.purchaserAbbreviation = ManageData.data.purchaserAbbreviation
        if (ManageData.data.onlineGoodsConfiguration == 1) {
          this.status1 = true
        }
        if (ManageData.data.transportationConfiguration == 1) {
          this.status = true
        }
        if (!!this.itemList.id && ManageData.data.transportationConfiguration == 0) {
          this.isShow = false
          this.isEdits = true
        }
        let res = await getPurOrderLinked(purId)
        if (res.data == 1) {
          if (this.linkedStatusFlag) {
            this.linkedStatus = false
          } else {
            this.linkedStatus = true
          }
        }
      },
      //获取供应商数据源
      async getSupList(purId) {
        try {
          let res = await getSupLists(purId)
          if (res.code == 0) {
            if (res.data.length > 0) {
              res.data.forEach(item => {
                this.supList.push({
                  value: item.id,
                  text: item.customerName,
                  supplierAbbreviation: item.supplierAbbreviation
                })
              })
              this.supplierOptions = [...this.supList]
            }
          }
        } catch (e) {
          return false;
        }
      },
      //获取煤源数据
      async getCoalSourceList() {
        try {
          let res = await getCoalSourceLists()
          if (res.code == 0) {
            if (res.data.length > 0) {
              res.data.forEach(item => {
                this.coalSourceList.push({
                  value: item.id,
                  label: item.coalSourceName
                })
              })
              this.filteredOptions = this.coalSourceList
            }
          }
        } catch (e) {
          return false;
        }
      },
      //获取采购订单数据
      async getPurOrderList(purId) {
        try {
          let res = await getCoalPurOrderLists(purId)
          if (res.code == 0) {
            if (res.data.length > 0) {
              res.data.forEach(item => {
                this.coalPurOrderList.push({
                  value: item.id,
                  label: item.purchaseOrderSourceName,
                  text: item.purchaseOrderSourceNo
                })
              })
              this.PurOrderOptions = this.coalPurOrderList
            }
          }
        } catch (e) {
          return false;
        }
      },
      //获取装货地数据源
      async getLoadList(data) {
        try {
          let res = await getLoadLists(data)
          if (res.code == 0) {
            if (res.data.length > 0) {
              res.data.forEach(item => {
                this.loadList.push({
                  value: item.id,
                  text: item.siteName
                })
              })
            }
          }
        } catch (e) {
          return false;
        }
      },
      //获取ERP订单数据源
      async getERPDataList(data) {
        try {
          let res = await getPlanERPDatas(data)
          if (res.code == 0) {
            if (res.data.length > 0) {
              res.data.forEach(item => {
                this.erpDataList.push({
                  value: item.billNo,
                  text: item.billName
                })
              })
            }
          }
        } catch (e) {
          return false;
        }
      },
      async handleLoadListChange(e) {
        if (this.loadList.length > 0) {
          this.itemList.loadingSiteName = this.loadList[e.detail.value].text
          this.itemList.loadingSiteId = this.loadList[e.detail.value].value
        }
      },
      async handleERPListChange(e) {
        if (this.erpDataList.length > 0) {
          this.itemList.billName = this.erpDataList[e.detail.value].text
          this.itemList.billNo = this.erpDataList[e.detail.value].value
        }
        if (e) {
          let res = await getERPMessLists(this.itemList.billNo)
          if(res.code == 0){
            this.itemList.supplierName = res.data.supName
            this.itemList.supId = res.data.supId
            this.searchSupplierText = res.data.supName
            this.itemList.supplierAbbreviation = res.data.supplierAbbreviation
            this.itemList.proName = res.data.proName
            this.itemList.proId = res.data.proId
            this.itemList.startTime = res.data.startTime
            this.itemList.endTime = res.data.endTime
            this.itemList.transportQuantity = res.data.planTotal
            this.itemList.productPrice = res.data.materialPrice
            this.erpMessDisabled = true
          }
        }
      },
      async handleLandChange(e) {
        if (this.landingPointNameList.length > 0) {
          this.itemList.landingPointName = this.landingPointNameList[e.detail.value].text
          this.itemList.landingPoint = this.landingPointNameList[e.detail.value].value
        }
      },

      //获取卸货地数据源
      async getDisChargeList(datas) {
        try {
          let res = await getDisChargeLists(datas)
          if (res.code == 0) {
            if (res.data.length > 0) {
              res.data.forEach(item => {
                this.dischargeList.push({
                  value: item.id,
                  text: item.siteName
                })
              })
            }
          }
        } catch (e) {
          return false;
        }
      },
      async handleDisChange(e) {
        if (this.dischargeList.length > 0) {
          this.itemList.landingPlace = this.dischargeList[e.detail.value].text
          this.itemList.landingPlaceId = this.dischargeList[e.detail.value].value
        }
      },
      resetDatas() {
        this.itemList.loadingSiteName = undefined
        this.itemList.loadingSiteId = undefined

        this.itemList.landingPlace = undefined
        this.itemList.landingPlaceId = undefined

        this.itemList.proName = undefined
        this.itemList.proId = undefined
      },
      async getProNameList(supId) {
        try {
          let res = await getProNameLists(supId)
          if (res.code == 0) {
            if (res.data.length > 0) {
              this.prochargeList = [];
              res.data.forEach(item => {
                this.prochargeList.push({
                  value: item.id,
                  text: item.proName,
                  price: item.proPrice
                })
              })
            }
          }
        } catch (e) {
          return false;
        }
      },
      async handleProChange(e) {
        if (this.erpMessDisabled) {
          return
        }
        if (this.prochargeList.length > 0) {
          this.itemList.proName = this.prochargeList[e.detail.value].text
          this.itemList.proId = this.prochargeList[e.detail.value].value
          this.itemList.productPrice = this.prochargeList[e.detail.value].price
        }
      },
      choseEndTimeFun() {
        if (this.erpMessDisabled || this.showErpFlag) {
          return
        }
        this.endTimePickerFlag=true
      },
      choseStartTimeFun() {
        if (this.erpMessDisabled || this.showErpFlag) {
          return
        }
        this.poundListFlag=true
      },
      async weitSettllChange(e) {
        if (this.weightSettlementList.length > 0) {
          this.weightSettBaName = this.weightSettlementList[e.detail.value].text
          this.itemList.weightSettlementBasis = this.weightSettlementList[e.detail.value].value
        }
      },
      async procuretMethodChange(e) {
        if (this.procurementMethodList.length > 0) {
          this.proMethodName = this.procurementMethodList[e.detail.value].text
          this.itemList.procurementMethod = this.procurementMethodList[e.detail.value].value
        }
      },
      async payReloadSetChange(e) {
        if (this.payReloadSetList.length > 0) {
          this.payRoadName = this.payReloadSetList[e.detail.value].text
          this.itemList.paymentRoadLossSetting = this.payReloadSetList[e.detail.value].value
        }
      },
      async planConfigMethodChange(e) {
        if (this.planConfigList.length > 0) {
          this.planConfigName = this.planConfigList[e.detail.value].text
          this.itemList.planConfig = this.planConfigList[e.detail.value].value
        }
      },
      async purchaseSalesChange(e) {
        if (this.purchaseSalesAttList.length > 0) {
          this.purchaseAndSalesAttName = this.purchaseSalesAttList[e.detail.value].text
          this.itemList.purchaseAndSalesAttributes = this.purchaseSalesAttList[e.detail.value].value
        }
      },
      handleSettlement(e) {
        if (this.settlementBasisList.length > 0) {
          this.settlementBasisName = this.settlementBasisList[e.detail.value].text
          this.itemList.settlementBasis = this.settlementBasisList[e.detail.value].value
        }
      },
      handleRoadLoss(e) {
        if (this.isCalculateRoadLossList.length > 0) {
          this.roadLossName = this.isCalculateRoadLossList[e.detail.value].text
          this.itemList.isCalculateRoadLoss = this.isCalculateRoadLossList[e.detail.value].value
        }
      },

      handleCalculateRule(e) {
        if (this.roadLossCalculateRuleList.length > 0) {
          this.calculateRuleName = this.roadLossCalculateRuleList[e.detail.value].text
          this.itemList.roadLossCalculateRule = this.roadLossCalculateRuleList[e.detail.value].value
        }
      },
      handlePaCalculateRule(e) {
        if (this.roadLossCalculateRuleList.length > 0) {
          this.paymentRuleName = this.roadLossCalculateRuleList[e.detail.value].text
          this.itemList.paymentRoadLossRule = this.roadLossCalculateRuleList[e.detail.value].value
        }
      },
      handleErasureRule(e) {
        if (this.erasureRuleList.length > 0) {
          this.erasureRuleName = this.erasureRuleList[e.detail.value].text
          this.itemList.erasureRule = this.erasureRuleList[e.detail.value].value
        }
      },
      handleNetCargoCompanyChange(e) {
        if (this.netCargoCompanyList.length > 0) {
          this.itemList.netCargoCompanyName = this.netCargoCompanyList[e.detail.value].text
          this.itemList.netCargoCompanyId = this.netCargoCompanyList[e.detail.value].value
        }
        //获取货主
        if (!!this.netCargoCompanyList[e.detail.value].value) this.getCargoOwnerList(this.netCargoCompanyList[e
          .detail.value].value);
      },

      async getCargoOwnerList(netCargoCompanyId) {
        try {
          let res = await getCargoownerLists(netCargoCompanyId)
          if (res.code == 0) {
            if (res.data.length > 0) {
              // 清空下拉框的数据
              this.cargoownerList = [];
              res.data.forEach(item => {
                this.cargoownerList.push({
                  value: item.id,
                  text: item.name,
                  networkFreightToken: item.networkFreightToken
                })
              })
            }
          }
        } catch (e) {
          return false;
        }
      },
      handleCargoOwnerChange(e) {
        if (this.cargoownerList.length > 0) {
          this.itemList.cargoOwnerName = this.cargoownerList[e.detail.value].text
          this.itemList.cargoOwnerId = this.cargoownerList[e.detail.value].value
          this.itemList.companyId = this.cargoownerList[e.detail.value].networkFreightToken
        }
        if (this.itemList.companyId) this.getAgentList(this.itemList.companyId);
      },
      async getAgentList(companyId) {
        try {
          let res = await getAgentLists(companyId)
          if (res.code == 0) {
            if (res.data.length > 0) {
              // 清空下拉框的数据
              this.agentList = [];
              res.data.forEach(item => {
                this.agentList.push({
                  value: item.id,
                  text: item.name
                })
              })
            }
          }
        } catch (e) {
          return false;
        }
      },

      async handleAgentChange(e) {
        if (this.agentList.length > 0) {
          this.itemList.agentName = this.agentList[e.detail.value].text
          this.itemList.agentId = this.agentList[e.detail.value].value
        }
      },
      async getDetail(id) {
        let data = await getPlanDetail(id)
        let _ = this
        if (data.code == 0) {
          if (data.data.purchaseOrderSourceName) {
            this.linkedStatus = true
            _.searchTextOne = data.data.purchaseOrderSourceName
          } else {
            this.linkedStatusFlag = true
          }
          _.itemList = data.data
          _.itemList.billNo = data.data.billNo
          _.itemList.billName = data.data.billName
          _.itemList.id = data.data.id
          _.itemList.purchaseId = data.data.purchaseId
          _.itemList.purchaser = data.data.purchaser
          _.itemList.productPrice = data.data.productPrice / 100
          _.itemList.coalSourceId = data.data.coalSourceId
          let selectedItem = this.filteredOptions.find(item => item.value === data.data.coalSourceId);
          if (selectedItem) {
            _.coalSourceName = selectedItem.label;
            _.searchText = selectedItem.label;
            _.itemList.coalSourceId = selectedItem.value;
          } else {
            _.searchText = '';
          }
          _.itemList.supId = data.data.supId
          _.searchSupplierText = data.data.supplierName
          _.itemList.supplierName = data.data.supplierName
          _.itemList.loadingSiteId = data.data.loadingSiteId
          _.itemList.loadingSiteName = data.data.loadingSiteName
          _.itemList.landingPlaceId = data.data.landingPlaceId
          _.itemList.landingPlace = data.data.landingPlace
          _.itemList.landingPoint = data.data.landingPoint
          _.itemList.landingPointName = data.data.landingPointName
          _.itemList.proId = data.data.proId
          _.itemList.proName = data.data.proName
     
          this.prochargeList.push({
            value: data.data.proId,
            text: data.data.proName
          })
          _.itemList.transportQuantity = data.data.transportQuantity
          _.itemList.startTime = data.data.startTime
          _.itemList.endTime = data.data.endTime
          _.itemList.purchaserPhone = data.data.purchaserPhone
          _.itemList.freight = data.data.freight
          _.itemList.updateFreight = data.data.freight
          _.itemList.settlementBasis = data.data.settlementBasis
          _.settlementBasisList.forEach(item => {
            if (item.value == data.data.settlementBasis) {
              _.settlementBasisName = item.text
            }
          })
          _.itemList.isCalculateRoadLoss = data.data.isCalculateRoadLoss
          _.isCalculateRoadLossList.forEach(item => {
            if (item.value == data.data.isCalculateRoadLoss) {
              _.roadLossName = item.text
            }
          })
          _.itemList.reasonableRoadLoss = data.data.reasonableRoadLoss
          _.itemList.roadLossPrice = data.data.roadLossPrice
          _.itemList.roadLossCalculateRule = data.data.roadLossCalculateRule
          _.roadLossCalculateRuleList.forEach(item => {
            if (item.value == data.data.roadLossCalculateRule) {
              _.calculateRuleName = item.text
            }
            if (item.value == data.data.paymentRoadLossRule) {
              _.paymentRuleName = item.text
            }
          })
          _.itemList.erasureRule = data.data.erasureRule
          _.erasureRuleList.forEach(item => {
            if (item.value == data.data.erasureRule) {
              _.erasureRuleName = item.text
            }
          })
          _.itemList.netCargoCompanyId = data.data.netCargoCompanyId

          _.itemList.netCargoCompanyName = data.data.netCargoCompanyName
          _.itemList.agentId = data.data.agentId
          _.itemList.cargoOwnerId = data.data.cargoOwnerId
          _.itemList.cargoOwnerName = data.data.cargoOwnerName
          _.itemList.agentName = data.data.agentName
          this.cargoownerList.push({
            value: data.data.cargoOwnerId,
            text: data.data.cargoOwnerName
          })
          this.agentList.push({
            value: data.data.agentId,
            text: data.data.agentName
          })

          this.itemList.weightSettlementBasis = data.data.weightSettlementBasis
          this.weightSettlementList.forEach(item => {
            if (item.value == data.data.weightSettlementBasis) {
              this.weightSettBaName = item.text
            }
          })
          this.itemList.procurementMethod = data.data.procurementMethod
          this.procurementMethodList.forEach(item => {
            if (item.value == data.data.procurementMethod) {
              this.proMethodName = item.text
            }
          })
          this.payReloadSetList.forEach(item => {
            if (item.value == data.data.paymentRoadLossSetting) {
              this.payRoadName = item.text
            }
          })
          this.planConfigList.forEach(item => {
            if (item.value == data.data.planConfig) {
              this.planConfigName = item.text
            }
          })
          this.sealPhotographList.forEach(item => {
            if (item.value == data.data.sealPhotograph) {
              this.sealPhotographName = item.text
            }
          })
          this.itemList.purchaseAndSalesAttributes = data.data.purchaseAndSalesAttributes
          this.purchaseSalesAttList.forEach(item => {
            if (item.value == data.data.purchaseAndSalesAttributes) {
              this.purchaseAndSalesAttName = item.text
            }
          })

          if (data.data.jyStatus == 0 || data.data.jyStatus == 1) {
            this.isShowBtns = true
          }
          this.isDisabled = true
        }
      },
      isValidTimeRange(startTime, endTime) {
        const startDateTime = new Date(startTime);
        const endDateTime = new Date(endTime);
        if (endDateTime < startDateTime) {
          return false;
        }

        return true;
      },
      isValidTime(endTime) {
        const currentTime = new Date();
        const endDateTime = new Date(endTime);
        if (endDateTime < currentTime) {
          return false;
        }
        return true;
      },
      formatTransportQuantity() {
        // 将输入值转换为保留两位小数的格式
        if (this.itemList.transportQuantity) {
          this.itemList.transportQuantity = parseFloat(this.itemList.transportQuantity).toFixed(2);
        }
      },
      formatFreight() {
        // 将输入值转换为保留两位小数的格式
        if (this.itemList.freight) {
          this.itemList.freight = parseFloat(this.itemList.freight).toFixed(2);
        }
      },
      //     validateTransportQuantity() {
      //         const regex = /^\d{1,6}(\.\d{1,2})?$/; // 匹配0到999999之间，最多两位小数的数字
      //         const quantity = this.itemList.transportQuantity;

      //         if (!regex.test(quantity)) {
      //             // 数量不符合要求
      //             uni.showToast({
      //                 title: '请输入范围在0.00-999999之间的数字，小数点后最多两位',
      //                 icon: 'none'
      //             });
      //             // 将输入框内容置为空
      //             this.itemList.transportQuantity = '';
      //         }
      //     },
      validatePhoneNumber() {
        const regex = /^[0-9]{8,11}$/; // 匹配8到11位数字
        const phoneNumber = this.itemList.purchaserPhone;

        if (!regex.test(phoneNumber)) {
          // 手机号码不符合要求
          toast(`请输入8到11位数字作为手机号码`)
          // uni.showToast({
          //     title: '请输入8到11位数字作为手机号码',
          //     icon: 'none'
          // });
        }
      },
      async handleUpdateClick() {
        let data = {}
        let msg = "更新运价"
        if (!this.itemList.updateFreight) {
          toast(`运价不能为空`)
          return
        } else {
          if (isNaN(this.itemList.updateFreight) || this.itemList.updateFreight < 0.00 || this.itemList
            .updateFreight > 999999) {
            toast(`运价必须为数字，并且在0.00-999999之间`)
            return
          }
        }
        if (this.itemList.id != undefined || this.itemList.id != '' || this.itemList.id != null) {
          let datas = {
            id: this.itemList.id,
            freight: this.itemList.updateFreight
          },
            data = await freightUpdate(datas)
          if (data.code == 0) {
            uni.showToast({
              title: msg + '成功',
              icon: 'success'
            });
            // uni.navigateTo({
            // 	url: '/pages/index'
            // });
            this.goBack();
          } else {
            uni.showToast({
              title: msg + '失败',
              icon: 'failed'
            });
          }
        }
      },
      async handleClick() {
        let res = {}
        let msg = ""
        if (this.showErpFlag) {
          if (!this.itemList.billNo) {
            toast(`请选择ERP订单`)
            return
          }
        }
        if ((!this.itemList.purchaseOrderSourceId || !this.searchTextOne) && this.linkedStatus) {
          toast(`请选择采购订单名称`)
          this.checkId = undefined
          this.itemList.supId = undefined
          this.searchSupplierText = undefined
          this.itemList.supplierName = undefined
          this.searchText = '请选择煤源'
          this.coalSourceName = undefined
          this.itemList.coalSourceId = undefined
          this.itemList.proId = undefined
          this.itemList.proName = undefined
          this.itemList.productPrice = undefined
          this.itemList.loadingSiteId = undefined
          this.itemList.loadingSiteName = undefined
          this.itemList.landingPlaceId = undefined
          this.itemList.landingPlace = undefined
          return
        } else {
          if (!(this.searchTextOne === this.itemList.purchaseOrderSourceName) && this.itemList.purchaseOrderSourceName) {
            toast(`请检查采购订单名称`)
            return
          }
        }
        if (!this.itemList.supId) {
          toast(`供应商不能为空`)
          return
        }
        if (!this.searchText || this.searchText == '请选择煤源') {
          this.itemList.coalSourceId = undefined
          toast(`请选择煤源`)
          return
        } else {
          if (!(this.searchText === this.coalSourceName)) {
            toast(`请检查煤源名称`)
            return
          }
        }
        if (!this.itemList.loadingSiteId) {
          toast(`装货地不能为空`)
          return
        }
        if (!this.itemList.landingPlaceId) {
          toast(`卸货地不能为空`)
          return
        }
        if (!this.itemList.proId) {
          toast(`产品不能为空`)
          return
        }
        if ([undefined, null].includes(this.itemList.productPrice)) {
          toast(`产品价格不能为空`)
          return
        } else {
          if (this.itemList.productPrice < 0 || this.itemList.productPrice > 999999.99) {
            toast(`请输入正确产品价格`)
            return
          }
        }

        if (!this.itemList.startTime) {
          toast(`开始时间不能为空`)
          return
        }
        if (!this.itemList.endTime) {
          toast(`结束时间不能为空`)
          return
        }
        if (!this.isValidTimeRange(this.itemList.startTime, this.itemList.endTime)) {
          toast(`结束时间不能早于开始时间`)
          return;
        }
        if (!this.isValidTime(this.itemList.endTime)) {
          toast(`结束时间不能早于当前时间`)
          return;
        }
        if (!this.itemList.transportQuantity) {
          toast(`拉运数量不能为空`)
          return
        } else {
          if (isNaN(this.itemList.transportQuantity) || this.itemList.transportQuantity < 0.00 || this
            .itemList.transportQuantity > 999999) {
            toast(`拉运数量必须为数字，并且在0.00-999999之间`)
            return
          }
        }
        if (!this.itemList.purchaserPhone) {
          toast(`收货人手机号不能为空`)
          return
        }
        if (this.itemList.paymentRoadLossSetting == 1) {
          if (!this.itemList.paymentRoadLoss) {
            toast(`货款合理路损不能为空`)
            return
          } else {
            if (isNaN(this.itemList.paymentRoadLoss) || this.itemList.paymentRoadLoss <
              0 || this.itemList.paymentRoadLoss > 999999.99) {
              toast(`货款合理路损必须为数字，并且在0.00-999999.99之间`)
              return
            }
          }
          if (!this.itemList.paymentRoadLossPrice) {
            toast(`货款合理路损单价不能为空`)
            return
          } else {
            if (isNaN(this.itemList.paymentRoadLossPrice) || this.itemList.paymentRoadLossPrice < 0 || this
              .itemList.paymentRoadLossPrice > 999999.99) {
              toast(`货款路损单价必须为数字，并且在0.00-999999.99之间`)
              return
            }
          }
        }
        if (this.status == true) {
          if (!this.itemList.freight) {
            toast(`运价不能为空`)
            return
          } else {
            if (isNaN(this.itemList.freight) || this.itemList.freight < 0.00 || this.itemList.freight >
              999999) {
              toast(`运价必须为数字，并且在0.00-999999之间`)
              return
            }
          }
          if (this.itemList.settlementBasis === undefined || this.itemList.settlementBasis === null) {
            toast(`结算依据不能为空`)
            return
          }
          if (this.itemList.isCalculateRoadLoss === undefined || this.itemList.isCalculateRoadLoss ===
            null) {
            toast(`是否计算路损不能为空`);
            return;
          } else {
            if (this.itemList.isCalculateRoadLoss == 0) {
              if (!this.itemList.reasonableRoadLoss) {
                toast(`合理路损不能为空`)
                return
              } else {
                if (isNaN(this.itemList.reasonableRoadLoss) || this.itemList.reasonableRoadLoss <
                  0.01 || this.itemList.reasonableRoadLoss > 999999) {
                  toast(`合理路损必须为数字，并且在0.01-999999之间`)
                  return
                }
              }
              if (!this.itemList.roadLossPrice) {
                toast(`路损单价不能为空`)
                return
              } else {
                if (isNaN(this.itemList.roadLossPrice) || this.itemList.roadLossPrice < 0.01 || this
                  .itemList.roadLossPrice > 999999) {
                  toast(`路损单价必须为数字，并且在0.01-999999之间`)
                  return
                }
              }
            }
          }
          if (this.itemList.erasureRule === undefined || this.itemList.erasureRule === null) {
            toast(`抹零规则不能为空`)
            return
          }
        }
        if (this.status1 == true) {
          if (!this.itemList.netCargoCompanyId) {
            toast(`网货公司不能为空`)
            return
          }
          if (!this.itemList.cargoOwnerId) {
            toast(`货主不能为空`)
            return
          }
          if (!this.itemList.agentId) {
            toast(`承运公司不能为空`)
            return
          }
        }
        msg = "添加"
        this.itemList.userId = this.userId
        // this.itemList.productPrice = this.itemList.productPrice * 100
        this.itemList.transportQuantity = parseFloat(this.itemList.transportQuantity);
        this.itemList.freight = parseFloat(this.itemList.freight);
        this.itemList.roadLossPrice = parseFloat(this.itemList.roadLossPrice);
        this.itemList.reasonableRoadLoss = parseFloat(this.itemList.reasonableRoadLoss);
        this.loading = true;
        let datas = { ...this.itemList, productPrice: this.itemList.productPrice * 100 }
        try {
          res = await createPlan(datas)
          if (res.code == 0) {
            uni.showToast({
              title: msg + '成功',
              icon: 'success'
            });
            this.goBack();
          } else {
            toast(res.msg)
          }
        } catch (error) {
          console.error('提交失败:', error);
          uni.showToast({
            title: '提交失败',
            icon: 'failed'
          });
        } finally {
          this.loading = false;
        }
      },
      onConfirm(res, type) {
        if(this.showErpFlag) return
        if (type === 'startTime') {
          this.itemList.startTime = res.result;
          this.poundListFlag = false;
        } else if (type === 'endTime') {
          this.itemList.endTime = res.result;
          this.endTimePickerFlag = false;
        }
      },
      async cancel() {
        console.log('id===============', this.itemList.id)
        this.$modal.confirm('确定取消吗?取消后将终止该计划!').then(() => {
          this.confirms();
        });
      },
      async confirms() {
        let res1 = await cancelPlanDetail({ id: this.itemList.id })
        if (res1.code == 0) {
          uni.showToast({
            title: '取消成功',
            icon: 'success',
            success: () => {

              setTimeout(() => {
                this.goBack();
              }, 1000);
            }
          });
        } else {
          uni.showToast({
            title: '取消失败',
            icon: 'failed'
          });
        }
      },
      onCancel() {
        this.poundListFlag = false
        this.endTimePickerFlag = false;
      },
      goBack() {
        wx.navigateBack({
          delta: 1,
        });
      },

      updatePrice(id) {
        uni.navigateTo({
          url: `/packageA/pages/common/transport-editing/adjustPrice?id=${id}`
        });
      },
      closePopup() {
        this.$refs.searchPopup.close();
      },

    }
  };
</script>

<style lang="scss" scoped>
  @import "@/static/scss/transplan.scss";

  .carList {
    border-radius: 0;
    padding: 10rpx;
    background-color: #f0f0f0;
    width: 63%;
    min-height: 190rpx;
    overflow: auto;
    font-size: 14px;
    position: absolute;
    top: 244px;
    z-index: 999;
    left: 122px;
    border: 1px solid #eee;

    .up-icon {
      color: #409EFE;
      cursor: pointer;
      text-align: right;
    }

    .a-i-c {
      position: relative;
      max-height: 398rpx;
      overflow: scroll;

      .car-box {
        margin-bottom: 102rpx;
      }

      .item-box {
        height: 30rpx;
        line-height: 30rpx;
        box-sizing: content-box;
        padding: 20rpx;
        font-size: 14px;
        border-bottom: 1px solid #eee;
        display: flex;
        justify-content: space-between;

        .cph {
          text-indent: 10rpx;
        }
      }
    }
  }

  .phxx-item-detail {
    padding-bottom: 163rpx;
  }

  .phxx-item {
    width: 700rpx;
    padding: 10rpx 30rpx;
    box-sizing: border-box;
    margin: 20rpx auto 20rpx auto;
    border-radius: 20rpx;
    background: #fff;
    font-size: 26.66rpx;
    color: #000;

    .phxx-item-content {
      width: 644rpx;

      .bottom {
        .title-box {
          padding: 30rpx 0 0 0;
          font-size: 30.22rpx;
        }

        // padding: 10rpx 0 0 0;
        >.items {
          padding-bottom: 4rpx;
          display: flex;
          align-items: center;
          border-bottom: 1px solid #ccc;
          padding-top: 15px;

          .net-selct-box {
            width: 77%;
          }
        }

        .btn {
          button {
            width: 100%;
            height: 40px !important;
            margin-top: 45px;
            line-height: 40px !important;
          }
        }

        .button {
          flex: 1;
          /* 将按钮的宽度均分 */
          height: 40px !important;
          line-height: 40px !important;
        }

        .cancel {
          margin-right: 10px;
          /* 设置取消按钮的右边距 */
        }

        .update {
          margin-left: 10px;
          /* 设置更新按钮的左边距 */
        }

        .til {
          width: 220rpx;
          display: inline-block;
        }

        .val {
          border: 1px solid #ccc;
          margin-left: 30rpx;
          width: 80%;
          display: inline-block;
          border-radius: 5px;
          height: 35px;
        }

        .searchPopup {
          position: absolute;
          right: 0;

          .up-searcbox {
            background: #fff;
            width: 800rpx;
            position: absolute;
            right: -195px;
            height: 30vh;
            padding: 30px;
            top: -200px;

            .search-header {
              .items {
                margin-bottom: 10px;

                input {
                  border: 1px solid #ccc;
                  border-radius: 3px;
                  height: 40px;
                  margin-top: 10px;
                  padding: 0 2px;
                  font-size: 24.88rpx;
                }
              }
            }

            .search-footer {
              bottom: 20%;
              position: absolute;
              display: flex;
              align-content: center;
              flex-flow: nowrap;

              button {
                width: 150px;
                float: right;
                font-size: 21.33rpx !important;
                border: 1px solid #409eff !important;
              }

              button:nth-child(2) {
                margin-left: 30px;
              }
            }
          }
        }
      }

      .demonstration {
        display: block;
        color: var(--el-text-color-secondary);
        font-size: 24.88rpx;
        margin-bottom: 20px;
        width: 100px;
      }
    }
  }

  .placeholder {
    color: #828282 !important;
  }

  .uni-input {
    color: #000;
  }

  .text-overflow-styl {
    white-space: nowrap;
    width: 90%;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .title {
    width: 226rpx !important;
  }

  .uni-select-box {
    padding-left: 14rpx !important;
    width: calc(100% - 226rpx) !important;
    position: relative;
  }

  .icons-box {
    position: absolute;
    top: 0;
    right: 4rpx;
  }
</style>